/* Page */
Page({
    data:{
        arr:[]
    },
    onLoad(){
        let url ="http://192.168.0.102:3000/top/playlist?cat=华语"
        console.log("onLoad");
        // wx-request
        wx.request({
            url,
            header: {'content-type':'application/json'},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: (res)=>{
                //获取所有的数据，放入playlists中
                let playlists = res.data.playlists;
                console.log("playlists数组");
                console.log(playlists);
                let arr = [];
                //遍历所有数据，把id,name ,coverImgUrl放到新数组中
                playlists.forEach((item,index)=>{
                    let {id,name,coverImgUrl} = item;
                    arr.push({
                        id,name,coverImgUrl
                    })
                })
                console.log(arr);
                this.setData({
                    arr:arr
                })
            }
        });
    },
    handleClick(event){
        let id = event.currentTarget.dataset.id;
        wx.navigateTo({
            url:`/pages/detail/detail?id=${id}`
        })

    }
})